<?php
namespace app\admin\controller;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);

use app\admin\Controller;
use mailer\tp5\Mailer;

class Company extends Controller
{
    use \app\admin\traits\controller\Controller;
    // 方法黑名单
    protected static $blacklist = [];

    public function upload(){
        if($this->request->isPost()){
            return '<s1cript>parent.layer.alert("仅做演示")</s1cript>'; // 去掉sc中间的1，markdown解析失败
            $result = \Qiniu::instance()->upload();
            p($result);die;
        }else{
            return $this->view->fetch('upload');
        }
    }

    public function email(){

        if($this->request->isAjax()){
            $receive = $this->request->post("receiver");
            $result = $this->validate(
                ['receiver' => $receive],
                ['receiver|收件人' => 'require|email']
            );
            if ($result !== true) {
                return ajax_return_adv_error($result);
            }
            $mailer = Mailer::instance();
            $result = $mailer->to($receive)
                ->subject('来自tpadmin的测试邮件')
                ->view('mail_template')
                ->send();

            if ($result == 0) {
                return ajax_return_adv_error($mailer->getError());
            } else {
                return ajax_return_adv("邮件发送成功，请注意查收", '');
            }
        }else{
            return $this->view->fetch('email');
        }

    }


}
